home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 February / PCpro_2005_02.ISO / files / opensource / A_Note_4.2.1 / setup.exe / {app} / Server Documents / createuser.php < prev    next >
Encoding:
PHP Script  |  2004-09-27  |  2.1 KB  |  82 lines

  1. <?php
  2. // Save the notes in the database
  3.  
  4. // Variable init
  5.     include ("init.php");
  6.  
  7. // Connect to the database    
  8.     include ("connect.php");
  9.  
  10. function get_string($h, $s, $e)
  11. {
  12. // Check that the start tag is NOT the same as the end tag
  13. if ($s == $e)
  14.    return "";
  15.  
  16. // Check that the start tag exists
  17. if (strpos ($h, $s, 0) === false)
  18.    return "";
  19.  
  20. // Check that the end tag exists
  21. if (strpos ($h, $e, 0) === false)
  22.    return "";
  23.  
  24. $sp = strpos($h, $s, 0) + strlen($s);  
  25. $ep = strpos($h, $e, 0); 
  26.  
  27. // Check that the start tag comes before the end tag
  28. if ($sp >= $ep)
  29.    return "";
  30.  
  31. return substr($h, $sp, $ep-$sp);
  32. }
  33.  
  34. // Get the xml
  35. $data = $HTTP_RAW_POST_DATA;
  36.  
  37. // Find the user information
  38.     $start = '<UserInformation>';
  39.     $end = '</UserInformation>';
  40.     $found = get_string($data, $start, $end);
  41.  
  42. // Get the data
  43.     $username        = get_string ($data, "<username>", "</username>");
  44.     $password        = get_string ($data, "<password>", "</password>");
  45.     $email            = get_string ($data, "<email>", "</email>");    
  46.     
  47. // See if the user already exists
  48.     $query="SELECT * FROM users WHERE user='$username'";
  49.     $reply = mysql_query ($query);
  50.     $num_result = mysql_num_rows ($reply);
  51.     if ($num_result != 0)    {
  52.         if (mysql_result ($reply, 0, "password") != $password)    {
  53.             echo $xmlstart ."<info info=\"username exists but wrong password\"/>";
  54.             exit;
  55.         }
  56.         else    {
  57.         // Update the user
  58.             $query ="UPDATE `users` SET `email` = '$email' WHERE user = '$username'";
  59.             mysql_query ($query);
  60.  
  61.             echo $xmlstart ."<info info=\"Creation of new user was successfull\"/>";
  62.             exit;
  63.         }
  64.     }
  65.  
  66. // Create the user
  67.  
  68.     $query = 'INSERT INTO `users` ( `id` , `user` , `password` , `email` , `numlogs` ) ';
  69.     $query .= 'VALUES ( \'\', \''.$username .'\', \'' .$password .'\', \''.$email .'\', \'0\' );';
  70.     $query .= ''; 
  71.     $reply = mysql_query ($query);
  72.     
  73. // Something went wrong
  74.     if ($reply === 0)    {
  75.         echo $xmlstart ."<info info=\"The user could not be created\"/>";
  76.         exit;
  77.     }
  78.  
  79. // Everytning is ok
  80. echo $xmlstart ."<info info=\"Creation of new user was successfull\"/>";
  81. ?>
  82.